<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :colon="false" :label-col="{ style: { width: '70px' } }">
        <a-form-item label="执行日期" class="w-72" name="dateRange">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="pyjm" class="w-72 ml-2">
          <a-input v-model:value="formState.pyjm" placeholder="员工编号/员工姓名/助记码" />
        </a-form-item>
        <a-form-item name="pyjm2" class="w-72 ml-2">
          <a-input v-model:value="formState.pyjm2" placeholder="处置项目名称/助记码" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-3">
        <BaseExport type="门诊" name="工作量统计" code="00001174" :search-params="formState">导出</BaseExport>
      </div>
      <BaseTable :loading="loading" column-code="00001174" fill :data-source="tableData" bordered :scroll="{ x: 1600 }" :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record.mc, gg: record.gg, cj: record.cj }" />
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickDetail(record)"> 明细 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Detail v-model:open="open" :row-data="rowData" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import Detail from './Detail'

const formRef = ref(null)
const formState = ref({
  dateRange: [dayjs(new Date().setDate(1)).format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const open = ref(false)
const rowData = ref({})
const onClickDetail = (record) => {
  rowData.value = { ...record, stdate: formState.value.dateRange?.[0], eddate: formState.value.dateRange?.[1] }
  open.value = true
}
const { loading, tableData, getData, pagination } = useTable({
  url: 'outp/mzhs/getWorkloadStatisticsRetrievalList',
  params: formState.value,
  immediate: true
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
